/*
 * Copyright (C) 2013 The i18nCTS Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.googlecode.i18nCTS.view;

import java.util.Calendar;

import android.text.format.DateUtils;
import android.util.Log;

import com.googlecode.i18nCTS.provider.i18nCTSProvider;
import com.googlecode.i18nCTS.util.i18nCTSUtils;

public class DateUtilsWeekdayTimeSectionFragment extends AbstractSectionFragment {
	private static final String TAG = "I18nCTS_" + DateUtilsWeekdayTimeSectionFragment.class.getSimpleName();
	public static final String CATEGORY = "DateUtils_WeekdayTime";
	static int flags = 0;

	public DateUtilsWeekdayTimeSectionFragment() {
		Log.d(TAG, "ctr");
	}

	void addDateWeekdayTime(i18nCTSProvider provider, long time1, long time2, int flag) {
		int flags = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_WEEKDAY;
		if (flag != 0) flags |= flag;
		
	    i18nCTSUtils utils = new i18nCTSUtils(mContext);
	    
		if (time1 == time2) 
			provider.addData(DateUtils.formatDateTime(mContext, time1, flags), utils.getParam(flags));
		else
			provider.addData(DateUtils.formatDateRange(mContext, time1, time2, flags), utils.getParam(flags));
	}	
	
    @SuppressWarnings("deprecation")
	void buildWeekdayTime(i18nCTSProvider provider, long time1, long time2) {
    	addDateWeekdayTime(provider, time1, time2, 0);
    	addDateWeekdayTime(provider, time1, time2, DateUtils.FORMAT_12HOUR);
    	addDateWeekdayTime(provider, time1, time2, DateUtils.FORMAT_12HOUR | DateUtils.FORMAT_CAP_AMPM);
    	addDateWeekdayTime(provider, time1, time2, DateUtils.FORMAT_24HOUR);
    	
    	addDateWeekdayTime(provider, time1, time2, DateUtils.FORMAT_ABBREV_WEEKDAY);
    	addDateWeekdayTime(provider, time1, time2, DateUtils.FORMAT_ABBREV_WEEKDAY | DateUtils.FORMAT_12HOUR);
    	addDateWeekdayTime(provider, time1, time2, DateUtils.FORMAT_ABBREV_WEEKDAY | DateUtils.FORMAT_12HOUR | DateUtils.FORMAT_CAP_AMPM);
    	addDateWeekdayTime(provider, time1, time2, DateUtils.FORMAT_ABBREV_WEEKDAY | DateUtils.FORMAT_24HOUR);

    	addDateWeekdayTime(provider, time1, time2, DateUtils.FORMAT_ABBREV_TIME | DateUtils.FORMAT_ABBREV_WEEKDAY);
    	addDateWeekdayTime(provider, time1, time2, DateUtils.FORMAT_ABBREV_TIME | DateUtils.FORMAT_ABBREV_WEEKDAY | DateUtils.FORMAT_12HOUR);
    	addDateWeekdayTime(provider, time1, time2, DateUtils.FORMAT_ABBREV_TIME | DateUtils.FORMAT_ABBREV_WEEKDAY | DateUtils.FORMAT_12HOUR | DateUtils.FORMAT_CAP_AMPM);
    	addDateWeekdayTime(provider, time1, time2, DateUtils.FORMAT_ABBREV_TIME | DateUtils.FORMAT_ABBREV_WEEKDAY | DateUtils.FORMAT_24HOUR);

    	addDateWeekdayTime(provider, time1, time2, DateUtils.FORMAT_ABBREV_ALL);
    	addDateWeekdayTime(provider, time1, time2, DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_12HOUR);
    	addDateWeekdayTime(provider, time1, time2, DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_12HOUR | DateUtils.FORMAT_CAP_AMPM);
    	addDateWeekdayTime(provider, time1, time2, DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_24HOUR);
    }

	@Override
	public String getCategory() {
		return CATEGORY;
	}
	
	@Override
	public void buildList(i18nCTSProvider provider) {
    	Calendar cal = Calendar.getInstance();
    	cal.set(2012, 1, 3, 4, 7);

    	Calendar cal2 = Calendar.getInstance();
		buildWeekdayTime(provider, cal.getTimeInMillis(), cal.getTimeInMillis());          
		
		cal2.set(2012, 1, 26, 14, 17); 
		buildWeekdayTime(provider, cal.getTimeInMillis(), cal2.getTimeInMillis());        
		
		cal2.set(2012, 10, 26, 15, 45);
		buildWeekdayTime(provider, cal.getTimeInMillis(), cal2.getTimeInMillis());        				
		
		cal2.set(2014, 1, 26, 22, 04);
		buildWeekdayTime(provider, cal.getTimeInMillis(), cal2.getTimeInMillis());        				
		
		cal2.set(2014, 10, 26, 23, 44);
		buildWeekdayTime(provider, cal.getTimeInMillis(), cal2.getTimeInMillis());        
		
		provider.addTitle(CATEGORY);
	}
}

